package com.ruoyi.business.controller;

import java.util.List;

import com.ruoyi.system.domain.vo.InnerObjVo;
import lombok.RequiredArgsConstructor;
import javax.servlet.http.HttpServletResponse;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.business.domain.TrainMan;
import com.ruoyi.business.service.ITrainManService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import org.springframework.validation.annotation.Validated;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 教练Controller
 * 
 * @author 吴倩芸
 * @date 2023-03-05
 */
@Validated
@RequiredArgsConstructor(onConstructor_ = @Autowired)
@RestController
@RequestMapping("/business/trainMan")
public class TrainManController extends BaseController
{
    @Autowired
    private ITrainManService trainManService;

    /**
     * 查询教练列表
     */
//    @PreAuthorize("@ss.hasPermi('business:trainMan:list')")
    @GetMapping("/list")
    public TableDataInfo list(TrainMan trainMan)
    {
        startPage();
        List<TrainMan> list = trainManService.selectTrainManList(trainMan);
        return getDataTable(list);
    }

    /**
     * 查询拥有高星数的教练
     * @return
     */
//    @PreAuthorize("@ss.hasPermi('business:trainMan:list')")
    @GetMapping("/highStar/list")
    public AjaxResult selectHighStarList(@RequestParam(value = "limit", defaultValue = "4") Integer limit) {
        List<TrainMan> list = trainManService.selectHighStarList(limit);
        return success(list);
    }

    /**
     * 导出教练列表
     */
//    @PreAuthorize("@ss.hasPermi('business:trainMan:export')")
    @Log(title = "教练", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, TrainMan trainMan)
    {
        List<TrainMan> list = trainManService.selectTrainManList(trainMan);
        ExcelUtil<TrainMan> util = new ExcelUtil<TrainMan>(TrainMan.class);
        util.exportExcel(response, list, "教练数据");
    }

    @Log(title = "根据教练的名字来查询用户的内部对象", businessType = BusinessType.OTHER)
    @GetMapping("/ref")
    public AjaxResult queryRefUserInnerObj(@RequestParam(value = "name", defaultValue = "") String name) {
        List<InnerObjVo> list = trainManService.queryRefTrainManInnerObj(name);
        return AjaxResult.success(list);
    }

    /**
     * 获取教练详细信息
     */
//    @PreAuthorize("@ss.hasPermi('business:trainMan:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return success(trainManService.selectTrainManById(id));
    }

    /**
     * 新增教练
     */
//    @PreAuthorize("@ss.hasPermi('business:trainMan:add')")
    @Log(title = "教练", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody TrainMan trainMan)
    {
        return toAjax(trainManService.insertTrainMan(trainMan));
    }

    /**
     * 修改教练
     */
//    @PreAuthorize("@ss.hasPermi('business:trainMan:edit')")
    @Log(title = "教练", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody TrainMan trainMan)
    {
        return toAjax(trainManService.updateTrainMan(trainMan));
    }

    /**
     * 删除教练
     */
//    @PreAuthorize("@ss.hasPermi('business:trainMan:remove')")
    @Log(title = "教练", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(trainManService.deleteTrainManByIds(ids));
    }
}
